<?php

namespace service;

use think\Controller;
use think\Log;
use think\Request;

/**
 * WIFI万能钥匙登录
 * Class WxmpService
 * @package service

 */
class WifiService
{
	
    /**
     * 当前访问网址
     * @var string
     */
    protected $url;

    protected $appid;

	protected $code;

	protected $md5key;


    /**
     * 初始化方法
     */
    public function _initialize($code)
    {
        // 当前完整URL地址
        $this->url = Request::instance()->url(true);
		$this->appid = "TD0250";
		$this->md5key = "r79tYYkxfTjCySf3qZn3LE2NkHq3vRyt";
		$this->code = $code;
    }

	/**
	 * Make an HTTP request
	 *
	 * @return string API results
	 * @ignore
	 */
	public function http($url, $data = array())
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		//如果是post请求
		if( is_array($data) )
		{
			curl_setopt($ch, CURLOPT_POST, 0);
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
		}
		$output = curl_exec($ch);
		curl_close($ch);
		return $output;
	}

	public function GetUrl($url)
	{
		//初始化curl
		$ch = curl_init();
		//设置超时
		curl_setopt($ch, CURLOPT_TIMEOUT, 10);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
		curl_setopt($ch, CURLOPT_HEADER, FALSE);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		
		//运行curl，结果以json形式返回
		$res = curl_exec($ch);
		curl_close($ch);
		//取出openid
		$data = json_decode($res,true);
		return $data;
	}
	

    /**
     * 获取AccessToken
     
     */
    public static function  getAccessToken()
    {
		$url = "https://wifi30.51y5.net/open-sso/fa.scmd";
		$pid="getAccessToken";
		$appId=$this->appid;
		$code=$this->code;
		$st = "m";
		$md5key = $this->md5key;
		$sign = md5($appId.$code.$pid.$st.$md5key);
		var_dump($code);
    }


}
